package jzoffer;

import java.util.Stack;

/**
 * 30 包含min函数的栈
 */
class MinStack {

    private Stack<Integer> stack;
    private Stack<Integer> b;
    /** initialize your data structure here. */
    public MinStack() {
        stack=new Stack();
        b=new Stack();
    }
    
    public void push(int x) {
        stack.push(x);

        if (b.isEmpty() || b.peek()>=x){
            b.push(x);
        }
    }


    public void pop() {
       if (stack.pop().equals(b.peek())){
           b.pop();
       }
    }
    
    public int top() {
        return stack.peek();
    }
    
    public int min() {
        return b.peek();
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(x);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.min();
 */